function tab(obj){
    if(event.keyCode==9){
        obj.value=obj.value+'    ';
        if(event && event.preventDefault){
            event.preventDefault();
        }else{
            window.event.returnValue=false;
        }
    }
}
let G = {};
let fj_num = $('#glfj>b');
    G.send_btn = $('#send-btn');
    G.inputs = $('[ns-data=true]');
    G.to_user = $('#to-user');
    G.to_user.change(function(){
        $(this).removeClass('err')
    });
    G.inputs.keydown(function(){
        $(this).removeClass('err')
    });
    G.send_btn.click(function(e){
        e ? e.preventDefault() : window.e.returnValue = false; 
        
        let sendcontent = $('#sendcontent');
        let sendtitle = $('#sendtitle');
        if($.trim(sendtitle.val()) === '' || sendtitle.val().length > 30){
            sendtitle.focus();
            sendtitle.addClass('err')
        }else if(!G.to_user.val()){
            G.to_user.addClass('err')
        }else if(fj_num.text() == 0 && $.trim(sendcontent.val()) === ''){
            sendcontent.focus();
            sendcontent.addClass('err')
        }else{
            let form = $("#myform")[0];
            let formdata = new FormData(form); 
            $.ajax({
                url: 'ajax/send.php',
                type: 'POST',
                dataType: 'json',
                processData: false,
                contentType: false,
                data: formdata
            })
            .done(function(data) {
                let hover_tip = $('#hover-tip');
                form.reset();
                hover_tip.text(data.msg);
                hover_tip.fadeIn();
                setTimeout(function(){
                    hover_tip.fadeOut();
                },1000)
            });
        }
        
    });
let glfj = $('#glfj');

let x = $('#x');
let up_list = $('#upload-zone');
glfj.click(function(event) {
     up_list.show()
});
x.click(function(event) {
    up_list.hide()
});
//文件上传
let currI = 0;

$('#add-fj').click(function() {
    currI++;
    $(this).prop('for','a'+currI);
    up_list.append(`<li class="hide"><input id="a${currI}" type="file" name="file[]"></li>`);
    $(`#a${currI}`).change(function(event) {
        let filename = this.files[0].name;
        let li = $(`<li><span class="file-name">${filename}</span><span class="file-action hand">删除</span></li>`);
        li.data('id', 'a'+currI);
        up_list.append(li);
        fj_num.text(parseInt(fj_num.text())+1);
    });
});
up_list.click(function(e) {
    if($(e.target).text() !== '删除'){
        return
    }
    let li = $(e.target).parent();
    $(`#${li.data('id')}`).parent().remove();
    li.remove();
    fj_num.text(parseInt(fj_num.text())-1);
});